#include "MyEventHandler.h"

bool MyEventHandler::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa){
    switch(ea.getEventType()) {
		case(GUIEventAdapter::KEYDOWN): { //KEYUP, DOUBLECLICK, DRAG
			// Eigene bewegung
			if(ea.getKey() == 'w' || ea.getKey() == 's' || ea.getKey() == 'd' || ea.getKey() == 'a' || ea.getKey() == 'q' || ea.getKey() == 'e' ||
					ea.getKey() == 'i' || ea.getKey() == 'k' || ea.getKey() == 'l' || ea.getKey() == 'j' || ea.getKey() == 'u' || ea.getKey() == 'o'){
				return bewegen->bewegung(ea, sceneHandler);
			}

			// Kamera Manipulatoren
			if(ea.getKey() == '1' || ea.getKey() == '2' || ea.getKey() == '3' || ea.getKey() == '4' || ea.getKey() == '5' || ea.getKey() == '6' ||
					ea.getKey() == '7' || ea.getKey() == '8' || ea.getKey() == '9' || ea.getKey() == '0' || ea.getKey() == 'p'){
				
				sceneHandler->getHud().removeTextBox(*sceneHandler->muhh);
				return kameraManipulator->kameraAuswahl(ea, sceneHandler);
			}

			switch(ea.getKey()){
				case 'y':
					if(kameraManipulatorON){
						sceneHandler->getHud().removeTextBox(*sceneHandler->cameraManipulatorText);
						kameraManipulatorON = false;
					}else{
						sceneHandler->getHud().addTextBox(*sceneHandler->cameraManipulatorText);
						kameraManipulatorON = true;
					}
					return false;
					break;
				case 'x':
					if(legendeON){
						sceneHandler->getHud().removeTextBox(*sceneHandler->legende);
						sceneHandler->getHud().removeTextBox(*sceneHandler->legendeBewegen);
						sceneHandler->getHud().removeTextBox(*sceneHandler->legendeSchauen);
						sceneHandler->getHud().removeTextBox(*sceneHandler->legendeManipulator);
						sceneHandler->getHud().removeTextBox(*sceneHandler->legendeLicht);
						legendeON = false;
					}else{
						sceneHandler->getHud().addTextBox(*sceneHandler->legende);
						sceneHandler->getHud().addTextBox(*sceneHandler->legendeBewegen);
						sceneHandler->getHud().addTextBox(*sceneHandler->legendeSchauen);
						sceneHandler->getHud().addTextBox(*sceneHandler->legendeManipulator);
						sceneHandler->getHud().addTextBox(*sceneHandler->legendeLicht);
						legendeON = true;
					}
					return false;
					break;
				case 'v':
					if(sonneMond){
						sceneHandler->lichtSonne->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::OFF );
						sceneHandler->lichtSonne2->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::OFF );
						sceneHandler->lichtMond->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::ON );
						sceneHandler->skyGroup->removeChild( sceneHandler->skyBoxTagTransform.get() );
						sceneHandler->skyGroup->addChild( sceneHandler->skyBoxNachtTransform.get() );
						sonneMond = false;
					}else{
						sceneHandler->lichtMond->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::OFF );
						sceneHandler->lichtSonne->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::ON );
						sceneHandler->lichtSonne2->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::ON );
						sceneHandler->skyGroup->removeChild( sceneHandler->skyBoxNachtTransform.get() );
						sceneHandler->skyGroup->addChild( sceneHandler->skyBoxTagTransform.get() );
						sonneMond = true;
					}
					return false;
					break;
				case 'r':
					if(alleHausLichter){
						sceneHandler->lichtWohnzimmer->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::OFF);
						sceneHandler->lichtKueche->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::OFF);
						sceneHandler->lichtSchlafzimmer->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::OFF);
						sceneHandler->lichtFlur->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::OFF);
						sceneHandler->lichtBad->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::OFF);
						alleHausLichter = false;
						lichtWohnzimmer = false;
						lichtKueche = false;
						lichtSchlafzimmer = false;
						lichtFlur = false;
						lichtBad = false;
					}else{
						sceneHandler->lichtWohnzimmer->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::ON);
						sceneHandler->lichtKueche->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::ON);
						sceneHandler->lichtSchlafzimmer->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::ON);
						sceneHandler->lichtFlur->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::ON);
						sceneHandler->lichtBad->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::ON);
						alleHausLichter = true;
						lichtWohnzimmer = true;
						lichtKueche = true;
						lichtSchlafzimmer = true;
						lichtFlur = true;
						lichtBad = true;
					}
					return false;
					break;
				case 't':
					if(lichtWohnzimmer){
						sceneHandler->lichtWohnzimmer->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::OFF);
						lichtWohnzimmer = false;
					}else{
						sceneHandler->lichtWohnzimmer->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::ON);
						lichtWohnzimmer = true;
					}
					return false;
					break;
				case 'z':
					if(lichtKueche){
						sceneHandler->lichtKueche->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::OFF);
						lichtKueche = false;
					}else{
						sceneHandler->lichtKueche->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::ON);
						lichtKueche = true;
					}
					return false;
					break;
				case 'f':
					if(lichtSchlafzimmer){
						sceneHandler->lichtSchlafzimmer->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::OFF);
						lichtSchlafzimmer = false;
					}else{
						sceneHandler->lichtSchlafzimmer->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::ON);
						lichtSchlafzimmer = true;
					}
					return false;
					break;
				case 'g':
					if(lichtFlur){
						sceneHandler->lichtFlur->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::OFF);
						lichtFlur = false;
					}else{
						sceneHandler->lichtFlur->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::ON);
						lichtFlur = true;
					}
					return false;
					break;
				case 'h':
					if(lichtBad){
						sceneHandler->lichtBad->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::OFF);
						lichtBad = false;
					}else{
						sceneHandler->lichtBad->setStateSetModes(*sceneHandler->lightGroup->getOrCreateStateSet(), StateAttribute::ON);
						lichtBad = true;
					}
					return false;
					break;
				case 'c':
					if(fog){
						sceneHandler->skyGroup->getOrCreateStateSet()->removeAttribute(sceneHandler->fog.get());
						fog = false;
					}else{
						sceneHandler->skyGroup->getOrCreateStateSet()->setAttributeAndModes( sceneHandler->fog.get() );
						fog = true;
					}
					return false;
					break;
				case 'm':
					if(kuhCamON){
						if(sceneHandler->viewer.getCameraManipulator() == NULL){
							sceneHandler->getHud().removeTextBox(*sceneHandler->muhh);
							sceneHandler->kuhCam = false;
							kuhCamON = false;
						}
						
					}else{
						if(sceneHandler->viewer.getCameraManipulator() == NULL){
							sceneHandler->getHud().addTextBox(*sceneHandler->muhh);
							sceneHandler->kuhCam = true;
							kuhCamON = true;
						}
					}
					return false;
					break;
				default:
					return false;
			}
		default:
			return false;
		}
	}
}